package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.WmsMaterialData;
import com.ruoyi.system.service.IWmsMaterialDataService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物料数据Controller
 * 
 * @author ruoyi
 * @date 2024-11-08
 */
@RestController
@RequestMapping("/system/data")
public class WmsMaterialDataController extends BaseController
{
    @Autowired
    private IWmsMaterialDataService wmsMaterialDataService;

    /**
     * 查询物料数据列表
     */
    @PreAuthorize("@ss.hasPermi('system:data:list')")
    @GetMapping("/list")
    public TableDataInfo list(WmsMaterialData wmsMaterialData)
    {
        startPage();
        List<WmsMaterialData> list = wmsMaterialDataService.selectWmsMaterialDataList(wmsMaterialData);
        return getDataTable(list);
    }

    /**
     * 导出物料数据列表
     */
    @PreAuthorize("@ss.hasPermi('system:data:export')")
    @Log(title = "物料数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsMaterialData wmsMaterialData)
    {
        List<WmsMaterialData> list = wmsMaterialDataService.selectWmsMaterialDataList(wmsMaterialData);
        ExcelUtil<WmsMaterialData> util = new ExcelUtil<WmsMaterialData>(WmsMaterialData.class);
        util.exportExcel(response, list, "物料数据数据");
    }

    /**
     * 获取物料数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:data:query')")
    @GetMapping(value = "/{materialId}")
    public AjaxResult getInfo(@PathVariable("materialId") Long materialId)
    {
        return success(wmsMaterialDataService.selectWmsMaterialDataByMaterialId(materialId));
    }

    /**
     * 新增物料数据
     */
    @PreAuthorize("@ss.hasPermi('system:data:add')")
    @Log(title = "物料数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmsMaterialData wmsMaterialData)
    {
        return toAjax(wmsMaterialDataService.insertWmsMaterialData(wmsMaterialData));
    }

    /**
     * 修改物料数据
     */
    @PreAuthorize("@ss.hasPermi('system:data:edit')")
    @Log(title = "物料数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmsMaterialData wmsMaterialData)
    {
        return toAjax(wmsMaterialDataService.updateWmsMaterialData(wmsMaterialData));
    }

    /**
     * 删除物料数据
     */
    @PreAuthorize("@ss.hasPermi('system:data:remove')")
    @Log(title = "物料数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{materialIds}")
    public AjaxResult remove(@PathVariable Long[] materialIds)
    {
        return toAjax(wmsMaterialDataService.deleteWmsMaterialDataByMaterialIds(materialIds));
    }
}
